/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl.edu.agh.student.logic.service;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import org.jboss.seam.annotations.In;
import org.jboss.seam.annotations.Name;
import org.jboss.seam.annotations.Out;
import pl.edu.agh.student.logic.dao.GenericDao;
import pl.edu.agh.student.logic.dao.RoleDao;
import pl.edu.agh.student.logic.dao.UserDao;
import pl.edu.agh.student.logic.service.GenericServiceImpl;
import pl.edu.agh.student.model.User;

/**
 *
 * @author janburkot
 */
@Name("userService")
public class UserServiceImpl extends GenericServiceImpl<User> implements UserService {
    
    @In(value="userDao",create=true,required=false)
    @Out
    protected UserDao dao;
    
    @In
    EntityManager entityManager;
    
    @Override
    public GenericDao<User> getDao() {
        return dao;
    }

    public User findByUsername(String username) {
        final Query query = entityManager.createQuery("select user from User user where username = :username")
                .setParameter("username", username);
        return (User)query.getSingleResult();
    }

}